
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/vector/coordsys.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:12 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>More about Coordinate Systems &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="coordsys.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Scalar and Vector Field Functionality" href="fields.html" />
    <link rel="prev" title="Basic Implementation details" href="basics.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="fields.html" title="Scalar and Vector Field Functionality"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="basics.html" title="Basic Implementation details"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Vector</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">More about Coordinate Systems</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="more-about-coordinate-systems">
<h1>More about Coordinate Systems<a class="headerlink" href="#more-about-coordinate-systems" title="Permalink to this headline">¶</a></h1>
<p>We will now look at how we can initialize new coordinate systems in
<a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a>, transformed in user-defined
ways with respect to already-existing systems.</p>
<section id="locating-new-systems">
<h2>Locating new systems<a class="headerlink" href="#locating-new-systems" title="Permalink to this headline">¶</a></h2>
<p>We already know that the <code class="docutils literal notranslate"><span class="pre">origin</span></code> property of a
<code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> corresponds to the <code class="docutils literal notranslate"><span class="pre">Point</span></code> instance
denoting its origin reference point.</p>
<p>Consider a coordinate system <span class="math notranslate nohighlight">\(N\)</span>. Suppose we want to define
a new system <span class="math notranslate nohighlight">\(M\)</span>, whose origin is located at
<span class="math notranslate nohighlight">\(\mathbf{3\hat{i} + 4\hat{j} + 5\hat{k}}\)</span> from <span class="math notranslate nohighlight">\(N\)</span>’s origin.
In other words, the coordinates of <span class="math notranslate nohighlight">\(M\)</span>’s origin from N’s perspective
happen to be <span class="math notranslate nohighlight">\((3, 4, 5)\)</span>. Moreover, this would also mean that
the coordinates of <span class="math notranslate nohighlight">\(N\)</span>’s origin with respect to <span class="math notranslate nohighlight">\(M\)</span>
would be <span class="math notranslate nohighlight">\((-3, -4, -5)\)</span>.</p>
<p>This can be achieved programmatically as follows -</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">locate_new</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="mi">5</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span><span class="o">.</span><span class="n">position_wrt</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="go">3*N.i + 4*N.j + 5*N.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">express_coordinates</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
<span class="go">(-3, -4, -5)</span>
</pre></div>
</div>
<p>It is worth noting that <span class="math notranslate nohighlight">\(M\)</span>’s orientation is the same as that of
<span class="math notranslate nohighlight">\(N\)</span>. This means that the rotation matrix of :math: <span class="math notranslate nohighlight">\(N\)</span> with respect
to <span class="math notranslate nohighlight">\(M\)</span>, and also vice versa, is equal to the identity matrix of
dimensions 3x3.
The <code class="docutils literal notranslate"><span class="pre">locate_new</span></code> method initializes a <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> that
is only translated in space, not re-oriented, relative to the ‘parent’
system.</p>
</section>
<section id="orienting-new-systems">
<h2>Orienting new systems<a class="headerlink" href="#orienting-new-systems" title="Permalink to this headline">¶</a></h2>
<p>Similar to ‘locating’ new systems, <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> also allows for
initialization of new <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> instances that are oriented
in user-defined ways with respect to existing systems.</p>
<p>Suppose you have a coordinate system <span class="math notranslate nohighlight">\(A\)</span>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>You want to initialize a new coordinate system <span class="math notranslate nohighlight">\(B\)</span>, that is rotated with
respect to <span class="math notranslate nohighlight">\(A\)</span>’s Z-axis by an angle <span class="math notranslate nohighlight">\(\theta\)</span>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">theta</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;theta&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The orientation is shown in the diagram below:</p>
<a class="reference internal image-reference" href="../../_images/coordsys_rot.svg"><img alt="../../_images/coordsys_rot.svg" class="align-center" height="250" src="../../_images/coordsys_rot.svg" width="250" /></a>
<p>There are two ways to achieve this.</p>
<section id="using-a-method-of-coordsys3d-directly">
<h3>Using a method of CoordSys3D directly<a class="headerlink" href="#using-a-method-of-coordsys3d-directly" title="Permalink to this headline">¶</a></h3>
<p>This is the easiest, cleanest, and hence the recommended way of doing
it.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">orient_new_axis</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">theta</span><span class="p">,</span> <span class="n">A</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<p>This initializes <span class="math notranslate nohighlight">\(B\)</span> with the required orientation information with
respect to <span class="math notranslate nohighlight">\(A\)</span>.</p>
<p><code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> provides the following direct orientation methods
in its API-</p>
<ol class="arabic simple">
<li><p><code class="docutils literal notranslate"><span class="pre">orient_new_axis</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">orient_new_body</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">orient_new_space</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">orient_new_quaternion</span></code></p></li>
</ol>
<p>Please look at the <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> class API given in the docs
of this module, to know their functionality and required arguments
in detail.</p>
</section>
<section id="using-orienter-s-and-the-orient-new-method">
<h3>Using Orienter(s) and the orient_new method<a class="headerlink" href="#using-orienter-s-and-the-orient-new-method" title="Permalink to this headline">¶</a></h3>
<p>You would first have to initialize an <code class="docutils literal notranslate"><span class="pre">AxisOrienter</span></code> instance for
storing the rotation information.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">AxisOrienter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">axis_orienter</span> <span class="o">=</span> <span class="n">AxisOrienter</span><span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="n">A</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<p>And then apply it using the <code class="docutils literal notranslate"><span class="pre">orient_new</span></code> method, to obtain <span class="math notranslate nohighlight">\(B\)</span>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">orient_new</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">axis_orienter</span><span class="p">)</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">orient_new</span></code> also lets you orient new systems using multiple
<code class="docutils literal notranslate"><span class="pre">Orienter</span></code> instances, provided in an iterable. The rotations/orientations
are applied to the new system in the order the <code class="docutils literal notranslate"><span class="pre">Orienter</span></code> instances
appear in the iterable.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">BodyOrienter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">body_orienter</span> <span class="o">=</span> <span class="n">BodyOrienter</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="s1">&#39;XYZ&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">orient_new</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="p">(</span><span class="n">axis_orienter</span><span class="p">,</span> <span class="n">body_orienter</span><span class="p">))</span>
</pre></div>
</div>
<p>The <a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> API provides the following four <code class="docutils literal notranslate"><span class="pre">Orienter</span></code>
classes for orientation purposes-</p>
<ol class="arabic simple">
<li><p><code class="docutils literal notranslate"><span class="pre">AxisOrienter</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">BodyOrienter</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">SpaceOrienter</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">QuaternionOrienter</span></code></p></li>
</ol>
<p>Please refer to the API of the respective classes in the docs of this
module to know more.</p>
<p>In each of the above examples, the origin of the new coordinate system
coincides with the origin of the ‘parent’ system.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">position_wrt</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>To compute the rotation matrix of any coordinate system with respect
to another one, use the <code class="docutils literal notranslate"><span class="pre">rotation_matrix</span></code> method.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">orient_new_axis</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">A</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">rotation_matrix</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[ cos(a), sin(a), 0],</span>
<span class="go">[-sin(a), cos(a), 0],</span>
<span class="go">[      0,      0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">rotation_matrix</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
</pre></div>
</div>
</section>
</section>
<section id="orienting-and-locating-new-systems">
<h2>Orienting AND Locating new systems<a class="headerlink" href="#orienting-and-locating-new-systems" title="Permalink to this headline">¶</a></h2>
<p>What if you want to initialize a new system that is not only oriented
in a pre-defined way, but also translated with respect to the parent?</p>
<p>Each of the <code class="docutils literal notranslate"><span class="pre">orient_new_&lt;method</span> <span class="pre">of</span> <span class="pre">orientation&gt;</span></code> methods, as well
as the <code class="docutils literal notranslate"><span class="pre">orient_new</span></code> method, support a <code class="docutils literal notranslate"><span class="pre">location</span></code> keyword
argument.</p>
<p>If a <code class="docutils literal notranslate"><span class="pre">Vector</span></code> is supplied as the value for this <code class="docutils literal notranslate"><span class="pre">kwarg</span></code>, the
new system’s origin is automatically defined to be located at that
position vector with respect to the parent coordinate system.</p>
<p>Thus, the orientation methods also act as methods to support orientation+
location of the new systems.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">orient_new_axis</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">A</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="mi">2</span><span class="o">*</span><span class="n">A</span><span class="o">.</span><span class="n">j</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">position_wrt</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">2*A.j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">express</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">express</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">position_wrt</span><span class="p">(</span><span class="n">C</span><span class="p">),</span> <span class="n">C</span><span class="p">)</span>
<span class="go">(-2*sin(a))*C.i + (-2*cos(a))*C.j</span>
</pre></div>
</div>
<p>More on the <code class="docutils literal notranslate"><span class="pre">express</span></code> function in a bit.</p>
</section>
<section id="transforming-new-system">
<h2>Transforming new system<a class="headerlink" href="#transforming-new-system" title="Permalink to this headline">¶</a></h2>
<p>The most general way of creating user-defined system is to use
<code class="docutils literal notranslate"><span class="pre">transformation</span></code> parameter in <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code>. Here we can define
any transformation equations. If we are interested in some typical
curvilinear coordinate system different that Cartesian, we can also
use some predefined ones. It could be also possible to translate or
rotate system by setting appropriate transformation equations.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">transformation</span><span class="o">=</span><span class="s1">&#39;spherical&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">transformation</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">:</span> <span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">x</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">z</span><span class="p">))</span>
</pre></div>
</div>
<p>In <code class="docutils literal notranslate"><span class="pre">CoordSys3D</span></code> is also dedicated method, <code class="docutils literal notranslate"><span class="pre">create_new</span></code> which works
similarly to methods like <code class="docutils literal notranslate"><span class="pre">locate_new</span></code>, <code class="docutils literal notranslate"><span class="pre">orient_new_axis</span></code> etc.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">create_new</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">transformation</span><span class="o">=</span><span class="s1">&#39;spherical&#39;</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="expression-of-quantities-in-different-coordinate-systems">
<h2>Expression of quantities in different coordinate systems<a class="headerlink" href="#expression-of-quantities-in-different-coordinate-systems" title="Permalink to this headline">¶</a></h2>
<section id="vectors-and-dyadics">
<h3>Vectors and Dyadics<a class="headerlink" href="#vectors-and-dyadics" title="Permalink to this headline">¶</a></h3>
<p>As mentioned earlier, the same vector attains different expressions in
different coordinate systems. In general, the same is true for scalar
expressions and dyadic tensors.</p>
<p><a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a> supports the expression of vector/scalar quantities
in different coordinate systems using the <code class="docutils literal notranslate"><span class="pre">express</span></code> function.</p>
<p>For purposes of this section, assume the following initializations-</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span><span class="p">,</span> <span class="n">express</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">orient_new_axis</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Vector</span></code> instances can be expressed in user defined systems using
<code class="docutils literal notranslate"><span class="pre">express</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v1</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">express</span><span class="p">(</span><span class="n">v1</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
<span class="go">(sin(a) + cos(a))*M.i + (-sin(a) + cos(a))*M.j + M.k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v2</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">M</span><span class="o">.</span><span class="n">j</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">express</span><span class="p">(</span><span class="n">v2</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
<span class="go">(1 - sin(a))*N.i + (cos(a))*N.j</span>
</pre></div>
</div>
<p>Apart from <code class="docutils literal notranslate"><span class="pre">Vector</span></code> instances, <code class="docutils literal notranslate"><span class="pre">express</span></code> also supports
reexpression of scalars (general SymPy <code class="docutils literal notranslate"><span class="pre">Expr</span></code>) and
<code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> objects.</p>
<p><code class="docutils literal notranslate"><span class="pre">express</span></code> also accepts a second coordinate system
for re-expressing <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code> instances.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">i</span> <span class="o">|</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span> <span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">j</span> <span class="o">|</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">express</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
<span class="go">(2*sin(a))*(M.i|M.i) + (2*cos(a))*(M.i|M.j) + 3*(M.j|M.k)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">express</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">M</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
<span class="go">2*(M.i|N.j) + 3*(M.j|N.k)</span>
</pre></div>
</div>
</section>
<section id="coordinate-variables">
<h3>Coordinate Variables<a class="headerlink" href="#coordinate-variables" title="Permalink to this headline">¶</a></h3>
<p>The location of a coordinate system’s origin does not affect the
re-expression of <code class="docutils literal notranslate"><span class="pre">BaseVector</span></code> instances. However, it does affect
the way <code class="docutils literal notranslate"><span class="pre">BaseScalar</span></code> instances are expressed in different systems.</p>
<p><code class="docutils literal notranslate"><span class="pre">BaseScalar</span></code> instances, are coordinate ‘symbols’ meant to denote the
variables used in the definition of vector/scalar fields in
<a class="reference internal" href="index.html#module-sympy.vector" title="sympy.vector"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.vector</span></code></a>.</p>
<p>For example, consider the scalar field
<span class="math notranslate nohighlight">\(\mathbf{{T}_{N}(x, y, z) = x + y + z}\)</span> defined in system <span class="math notranslate nohighlight">\(N\)</span>.
Thus, at a point with coordinates <span class="math notranslate nohighlight">\((a, b, c)\)</span>, the value of the
field would be <span class="math notranslate nohighlight">\(a + b + c\)</span>. Now consider system <span class="math notranslate nohighlight">\(R\)</span>, whose
origin is located at <span class="math notranslate nohighlight">\((1, 2, 3)\)</span> with respect to <span class="math notranslate nohighlight">\(N\)</span> (no
change of orientation).
A point with coordinates <span class="math notranslate nohighlight">\((a, b, c)\)</span> in <span class="math notranslate nohighlight">\(R\)</span> has coordinates
<span class="math notranslate nohighlight">\((a + 1, b + 2, c + 3)\)</span> in <span class="math notranslate nohighlight">\(N\)</span>.
Therefore, the expression for <span class="math notranslate nohighlight">\(\mathbf{{T}_{N}}\)</span> in <span class="math notranslate nohighlight">\(R\)</span> becomes
<span class="math notranslate nohighlight">\(\mathbf{{T}_{R}}(x, y, z) = x + y + z + 6\)</span>.</p>
<p>Coordinate variables, if present in a vector/scalar/dyadic expression,
can also be re-expressed in a given coordinate system, by setting the
<code class="docutils literal notranslate"><span class="pre">variables</span></code> keyword argument of <code class="docutils literal notranslate"><span class="pre">express</span></code> to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<p>The above mentioned example, done programmatically, would look like
this -</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">locate_new</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">N</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T_N</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">y</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">express</span><span class="p">(</span><span class="n">T_N</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> <span class="n">variables</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">R.x + R.y + R.z + 6</span>
</pre></div>
</div>
</section>
<section id="other-expression-dependent-methods">
<h3>Other expression-dependent methods<a class="headerlink" href="#other-expression-dependent-methods" title="Permalink to this headline">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">to_matrix</span></code> method of <code class="docutils literal notranslate"><span class="pre">Vector</span></code> and
<code class="docutils literal notranslate"><span class="pre">express_coordinates</span></code> method of <code class="docutils literal notranslate"><span class="pre">Point</span></code> also return
different results depending on the coordinate system being provided.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">R</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">locate_new</span><span class="p">(</span><span class="s1">&#39;P&#39;</span><span class="p">,</span> <span class="n">a</span><span class="o">*</span><span class="n">R</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">R</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">c</span><span class="o">*</span><span class="n">R</span><span class="o">.</span><span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">express_coordinates</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="go">(a + 1, b + 2, c + 3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">express_coordinates</span><span class="p">(</span><span class="n">R</span><span class="p">)</span>
<span class="go">(a, b, c)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">N</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">N</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span><span class="o">.</span><span class="n">to_matrix</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[ sin(a) + cos(a)],</span>
<span class="go">[-sin(a) + cos(a)],</span>
<span class="go">[               1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span><span class="o">.</span><span class="n">to_matrix</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1],</span>
<span class="go">[1],</span>
<span class="go">[1]])</span>
</pre></div>
</div>
</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">More about Coordinate Systems</a><ul>
<li><a class="reference internal" href="#locating-new-systems">Locating new systems</a></li>
<li><a class="reference internal" href="#orienting-new-systems">Orienting new systems</a><ul>
<li><a class="reference internal" href="#using-a-method-of-coordsys3d-directly">Using a method of CoordSys3D directly</a></li>
<li><a class="reference internal" href="#using-orienter-s-and-the-orient-new-method">Using Orienter(s) and the orient_new method</a></li>
</ul>
</li>
<li><a class="reference internal" href="#orienting-and-locating-new-systems">Orienting AND Locating new systems</a></li>
<li><a class="reference internal" href="#transforming-new-system">Transforming new system</a></li>
<li><a class="reference internal" href="#expression-of-quantities-in-different-coordinate-systems">Expression of quantities in different coordinate systems</a><ul>
<li><a class="reference internal" href="#vectors-and-dyadics">Vectors and Dyadics</a></li>
<li><a class="reference internal" href="#coordinate-variables">Coordinate Variables</a></li>
<li><a class="reference internal" href="#other-expression-dependent-methods">Other expression-dependent methods</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="basics.html"
                        title="previous chapter">Basic Implementation details</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="fields.html"
                        title="next chapter">Scalar and Vector Field Functionality</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/vector/coordsys.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="fields.html" title="Scalar and Vector Field Functionality"
             >next</a> |</li>
        <li class="right" >
          <a href="basics.html" title="Basic Implementation details"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Vector</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">More about Coordinate Systems</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/vector/coordsys.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:12 GMT -->
</html>